#!/bin/bash
{% set host="-".join(inventory_hostname.split('.')) %}
{% set groups=hostvars[inventory_hostname]['groups'] %}
{% for line in groups %}
{% if  line != 'all' and line !='ungrouped' and  inventory_hostname in  groups[line] %}
# {{ENV}}-{{line}}-{{host}}

curl -X PUT -d '{
"id": "{{ENV}}-{{line}}-{{host}}",
"name": "node-exporter", 
"address": "{{inventory_hostname}}",
"port": 9100,
"tags": ["linux"], 
"meta": { 
   "group": "{{line}}", 
   "environment": "Pro", 
   "project": "{{ENV}}"
 },
"checks": [ {
    "http": "http://{{inventory_hostname }}:9100/metrics",
    "interval": "5s"
  }]}' \
http://10.147.134.217:8500/v1/agent/service/register

{% endif %}
{% endfor %}
